<div>
	<div class="ui-widget-content ui-corner-all" style="margin: 8px; width: 200px; padding:5px; float: right;"> 
		<h3 class="ui-widget-header" style="margin-top: 0; text-align: center;"> Štatistiky </h3>
		<div style="padding: 5px; padding-top: 0;">
			Memcache status: <span id="mem_status">N/a</span><br/>
			Memcache load: <span id="mem_load">N/a</span><br/>
			Memcached items: <span id="mem_items">N/a</span><br/>
			<input type="button" class="button" onclick="memcacheFlush();" value="Clean Memcache"/>  
			<hr />
			Order count: <span id="order_count">N/a</span><br/>
			Ordered seats: <span id="seat_count">N/a</span><br/>
			Registered users: <span id="user_count">N/a</span><br/>
			<hr />
			<input type="button" class="button" value="Refresh" onclick="GetStatistics();"/> 
		</div>
	</div>
</div>
{literal}
<script type="text/javascript">
	function GetStatistics(){
		$.ajax({
			data: {
				controller: "order_administration/statistics",
				action: "statistics",
			},
			success: function(data){
				console.log(data);
				if (data.memcache_active){
					$("#mem_status").css("color", "green").html("Running");
					$("#mem_load").html((data.memcache_load + "").slice(0, 5) + "%");
					$("#mem_items").html(data.memcache_items);
				} else {
					$("#mem_status").css("color", "red").html("Down");
					$("#mem_items").css("color", "red").html("N/a");
					$("#mem_load").css("color", "red").html("N/a");
				}
				$("#order_count").html(data.order_count);
				$("#seat_count").html(data.seat_count);
				$("#user_count").html(data.user_count);
			},
			error: function(data){
				console.log(data);
			}
		});
	}
	
	function memcacheFlush(){
		$.ajax({
			data: {
				action: "flush",
				controller: "order_administration",
			},
			success: function(data){
				alert("Memcache cleared");
				GetStatistics();
			}
		});
	}
	
	$(function(){
		GetStatistics();
		$(".button").button();
	})
	
</script>
{/literal}
